home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1989 / Jun 89 / V0056-Re Obj. Pascal-Jun89 < prev    next >
Encoding:
Text File  |  1991-03-06  |  3.7 KB  |  81 lines  |  [TEXT/GEOL]

  1. Item    5267281                         20-June-89        16:48
  2.  
  3. From:   ROSENSTEIN1                     Rosenstein, Larry
  4.  
  5. To:     D2086                           Efficient Field Svc, C Faith, PRT
  6.  
  7. cc:     MACAPP.TECH$                    MACAPP Tech
  8.  
  9. Sub:    Re: Obj. Pascal
  10.  
  11. (1) You cannot easily tell whether a method was called "normally" or via
  12. INHERITED.  I suppose you could get the return address, find the JSR
  13. instruction that called the method, and see if the JSR was to the method
  14. dispatcher or directly to the method.  (Every INHERITED call results in a
  15. direct JSR to the method.)
  16.  
  17. I don't think this would be a good feature to have in Object Pascal; your code
  18. shouldn't care if a method is called directly or via INHERITED.
  19.  
  20. It is hard to comment on your particular example, without knowing what the code
  21. does, but it sounds like TAbstract.DoSomething is intended to do something
  22. different from TConcrete.DoSomething.  In that case, I would define a new
  23. method to do the work, and make TAbstract.DoSomething call ProgramBreak (when
  24. debugging code is turned on).
  25.  
  26.  
  27. (2) Segmentation does not determine whether a method call requires dispatching
  28. or not.  In your example, the fact that MainMethod and AuxMethod are in the
  29. same segment doesn't change the fact that the compiler can't tell which
  30. implementation of AuxMethod is being called.
  31.  
  32. The linker can (sometimes) tell which implementation will be called, and if you
  33. compile an optimized version it will change those method calls into direct
  34. JSRs.  The most command case is when there is only one implementation of
  35. AuxMethod; clearly if there is one implementation it is easy to tell what the
  36. target of the call will be.
  37.  
  38. In theory, any method call for which the linker can determine the exact method
  39. that will be called could be optimized to a direct JSR.  For example, suppose
  40. the method TFoo.MainMethod is running and it calls SELF.AuxMethod.  If TFoo has
  41. no subclasses then SELF must be a TFoo object.  Therefore, the linker could
  42. change the SELF.AuxMethod call to a direct JSR.
  43.  
  44. I don't know if the linker is smart enough to do this, however.
  45.  
  46. I can say something about the Object Pascal dispatching scheme, as I understand
  47. it.  (If things have changed, hopefully someone will post new info.)  I will
  48. focus on the optimized scheme, since a shipping product would use that scheme.
  49.  
  50. The method tables are organized by method.  That is, there is a table for each
  51. method which contains all the implementations of that method.  The table is
  52. normally searched linearly, so the average dispatching overhead depends on the
  53. number of implementations of a method.
  54.  
  55. As I mentioned above, if there is only one implementation, then the overhead is
  56. 0 because the linker will change the call into a direct JSR.  (When I say
  57. overhead, I mean extra time above and beyond a JSR.)
  58.  
  59. I did some performance measurements a few months ago, and got a figure of about
  60. 80 microseconds of overhead for a method call.  This was with a method having 6
  61. implementations.
  62.  
  63. Object Pascal can sometimes do better than this, because it caches the class
  64. and code address each time a call is made to a method.  If you call the method
  65. with and object of the same class, the second call will be much faster.  My
  66. measurements indicated 31 microseconds of overhead if the method has been
  67. cached.  (Each method has its own cache.)
  68.  
  69. I also measured the overhead of a ROM trap at 31 microseconds.
  70.  
  71. In general, Object Pascal imposes a dispatching overhead proportional to the
  72. "amount" of polymorphism you use.  The dispatching overhead for the call x.Foo
  73. will be larger if you have 20 implementations of Foo.  But presumably any of
  74. those implementations could be executed by that call.  If you only have one
  75. implementation, then the overhead will be 0.
  76.  
  77. Larry Rosenstein
  78.  
  79.  
  80.  
  81.